package gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Stack;
import java.util.StringTokenizer;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;

import logic.Facade;
import data.SystemData;
import data.UserTuple;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class frmMain extends javax.swing.JFrame {
	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	private JMenuItem goToUserPanel;
	private JMenuBar jMenuBar1;
	private JMenu jMenu1;
	private JPanel _currPanel;
	private Stack<JPanel> _oldPanels;

	public frmMain() {
		super();
		_oldPanels = new Stack<JPanel>();
		_currPanel=null;
		initGUI();
	}

	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{
				jMenuBar1 = new JMenuBar();
				setJMenuBar(jMenuBar1);
				jMenu1 = new JMenu("User");
				jMenuBar1.add(jMenu1);
				goToUserPanel = new JMenuItem("Logout");
				goToUserPanel.addActionListener(new ActionListener(){
						public void actionPerformed(ActionEvent e){
							Facade.getInstance().logout(/*s*/);
						}

					});
				jMenu1.add(goToUserPanel);
			}
			changeScreen(new pnlLogin());
			this.setSize(793, 549);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void changeScreen(JPanel panel){
		if (_currPanel!=null)
			_oldPanels.push(_currPanel);
		_currPanel = panel;
		JScrollPane tmp =  new JScrollPane(panel);
		setContentPane(tmp);
		pack();
	}

	public void back(){
		if (_oldPanels.empty()){
			return;
		}
		JPanel oldp = _oldPanels.pop();
		_currPanel=oldp;
		JScrollPane tmp =  new JScrollPane(oldp);
		setContentPane(tmp);
		pack();
	}

	public void showMovieScreen(String string, String user) {
		changeScreen(new pnlMovieDisplay(Facade.getInstance().getMovieData(string),user));

	}


	public void showUserScreenAfterRating(String user, boolean isAdmin) {
		changeScreen(new pnlUserPanel(user, isAdmin, "Thank you for rating!!!"));

	}

	public void showLoginScreen() {
		changeScreen(new pnlLogin());
	}

	public void showDeleteUserScreen(String user) {
		changeScreen(new pnlRemoveUser(user));

	}

	public void showDeleteMovieScreen(String user) {
		changeScreen(new pnlRemoveMovie(user));
	}

	public void showAddMovieScreen(String user) {
		changeScreen(new pnlMovieAddition(user));
	}

	public void showUserScreenAfterChangeDetails(String name, boolean admin) {
		changeScreen(new pnlUserPanel(name, admin , "Details changed succesfully"));
		
	}

	public void showChangeDetailsScreen(String user) {
		UserTuple t = SystemData.getInstance().getUser(user);
		StringTokenizer bd = new StringTokenizer(t.get_bdate(), "/");
		System.out.println("t.is_sex() "+ t.is_sex());
		changeScreen(new pnlChangeDetails(user, (t.is_sex() ? "Female" : "Male") , bd.nextToken(), bd.nextToken(), bd.nextToken() ));
		
	}

}
